#include "los_task.h"
#include "los_compiler.h"
#include "cmsis_os2.h"
#include "ohos_init.h"
#include "ohos_types.h"
#include "unistd.h"
#include "sys/types.h"
#include "fcntl.h"
#include "errno.h"

void hal_fs_entry()
{
    printf("----- fs test -----\n");
    // 打开文件
    int fd = HalFileOpen("hal_test.txt", O_RDWR|O_CREAT, 0777);
    if(fd < 0)
    {
        printf("file open error %d\n", errno);
        return;
    }
    // 写入数据
    printf("write buf hello\n");
    int ret1 = HalFileWrite(fd, "hello", 5);
    UINT8 buf[6]={0};
    // 定位到文件开始
    HalFileSeek(fd, 0, SEEK_SET);
    // 读取数据
    int ret2 = HalFileRead(fd, buf, 5);
    printf("read buf %s\n", buf);
}

void hal_fs_task()
{
    UINT32 uwRet = -1;
    UINT32 taskID = 0;
    TSK_INIT_PARAM_S stTask = {0};
    stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)hal_fs_entry;
    stTask.uwStackSize = 0x1000;
    stTask.pcName = "fs task";
    stTask.usTaskPrio = 10;
    uwRet = LOS_TaskCreate(&taskID, &stTask);
    if (uwRet != LOS_OK) {
        printf("Task fs create failed\n");
    }
}